package com.hsck.order.kds.main.dialog

import android.content.Context
import android.view.View
import androidx.core.view.GravityCompat
import androidx.drawerlayout.widget.DrawerLayout
import androidx.recyclerview.widget.LinearLayoutManager
import com.hjq.toast.Toaster
import com.hsck.order.kds.R
import com.hsck.order.kds.base.utils.LogUtil
import com.hsck.order.kds.setup.adapter.PrinterAdapter
import kotlinx.android.synthetic.main.item_personal.view.*
import kotlinx.android.synthetic.main.item_printer.view.*

object PrinterDl {

    private val adapter by lazy { PrinterAdapter(R.layout.item_printers) }

    fun show(context: Context, viewTop: View, dl: DrawerLayout) {
        val view = viewTop.lin_printer
        viewTop.lin_personal.visibility = View.GONE
        view.visibility = View.VISIBLE
        dl.addDrawerListener(object : DrawerLayout.DrawerListener {
            override fun onDrawerSlide(drawerView: View, slideOffset: Float) {
            }

            override fun onDrawerOpened(drawerView: View) {
                LogUtil.i("onDrawerOpened")
                drawerView.isClickable = true
            }

            override fun onDrawerClosed(drawerView: View) {
            }

            override fun onDrawerStateChanged(newState: Int) {
            }

        })

        dl.addDrawerListener(object : DrawerLayout.DrawerListener {
            override fun onDrawerSlide(p0: View, p1: Float) {
                // 滑动时调用
            }

            override fun onDrawerOpened(p0: View) {
                // 当滑动菜单完全打开时调用
            }

            override fun onDrawerClosed(p0: View) {
                // 当滑动菜单完全关闭时调用
            }

            override fun onDrawerStateChanged(p0: Int) {
                // 滑动状态改变时调用
            }

        })
        view.img_item_printer_close.setOnClickListener {
            dl.closeDrawer(GravityCompat.END)
        }

        view.rv_item_printer.layoutManager = LinearLayoutManager(context)
        view.rv_item_printer.adapter = adapter
        adapter.datas = listOf("", "", "", "", "")

        adapter.onDelOnClick = {
            Toaster.show("删除")
        }

        adapter.onPrinterOnClick = {
            Toaster.show("重新打印")
        }
    }


}